package demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Query {

	public static void main(String[] args) throws Exception {
		// System.out.println("hello,csvsql");

		String file = "/Users/dugang/work/csvsql/docs/";
		Class.forName("org.relique.jdbc.csv.CsvDriver");
		Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + file);

		// create a scrollable Statement so we can move forwards and backwards
		// through ResultSets
		Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
		ResultSet results = stmt.executeQuery("SELECT id,name,age,height,weight FROM pets");

		while (results.next()) {

			System.out.println(results.getLong(1) + " " + results.getString(2) + " " + results.getInt(3) + " "
					+ results.getInt(4) + " " + results.getDouble(5));
		}
		
		// 	

		results.close();
		
		System.out.println("******");
		
		results = stmt.executeQuery("SELECT id,name,age,height,weight FROM pets");

		while (results.next()) {

			System.out.println(results.getLong("id") + " " + results.getString("name"));
		}
		
		results.close();
		
		System.out.println("******");

		
		results = stmt.executeQuery("SELECT id,name,age,height,weight FROM pets where age > 3 ");

		while (results.next()) {
			System.out.println(results.getLong("id") + " " + results.getString("name"));
		}
		
		results.close();

		
		stmt.close();
		conn.close();

	}
}
